import { Body, Controller, Get, Post, Request, UseGuards } from '@nestjs/common';
import { AuthService } from './auth.service';
import RegisterDto from './dto/register.dto';
import {hash} from 'argon2'
import LoginDto from './dto/login.dto';
import { ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';

@Controller('auth')
@ApiTags('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}
  
  // 注册
  @Post('register')
  register(@Body() dto: RegisterDto) {
 
    console.log('注册请求体', dto);
    return this.authService.register(dto);
  }
  @Post('login')
  login(@Body() dto: LoginDto) {

    console.log('登录请求体', dto);
    return this.authService.login(dto);
  }

  // 受保护的路由，需要JWT token验证
  @UseGuards(AuthGuard('jwt'))
  @Get('profile')
  getProfile(@Request() req) {
    return req.user;
  }
}
